package org.miku.module.note;

import java.util.List;

public class PageManager {
	private static final int MAX_PAGE_COUNT = 10;
	
	private NoteManager noteMgr = null;
	private int mPage = 0;
	
	public PageManager(NoteManager noteManager, int page) {
		noteMgr = noteManager;
		mPage = page;
	}
	
	public List<NoteInfo> getData() {
		List<NoteInfo> list = null;
		int count = noteMgr.getNoteCount();
		int index = getIndex(count);
		if(index < count) {
			list = noteMgr.getNoteList(index, MAX_PAGE_COUNT);
		}
		return list;
	}
	
	public int getPageCount() {
		int pageCount = 0;
		int recordCount = noteMgr.getNoteCount();
		if(recordCount > 0) {
			pageCount = recordCount / MAX_PAGE_COUNT;
			// Increase the count of page if there have remain something.
			pageCount += (recordCount % MAX_PAGE_COUNT) != 0 ? 1 : 0;
		}
		return pageCount;
	}
	
	private int getIndex(int count) {
		// Increasing from zero
		return mPage * MAX_PAGE_COUNT;
	}
}
